import React, { PureComponent } from 'react'
import { connect } from 'react-redux'
import {subNumber} from '../store/features/counter'
import { fetchHomeMultidataAction } from '../store/features/home'

export class home extends PureComponent {
  componentDidMount(){
    this.props.fetchHomeMultidata()
  }

  subNumber(num){
    this.props.subNumber(num)
  }

  render() {
    const {counter} = this.props
    return (
      <div>
        <h1>home :{counter}</h1>
        <button onClick={e=>this.subNumber(5)}>-5</button>
        <button onClick={e=>this.subNumber(10)}>-10</button>
      </div>
    )
  }
}
const mapStateToProps = (state)=>({
  counter:state.counter.counter
})
const mapDispatchToProps = (dispatch)=>({
  subNumber(num){
    dispatch(subNumber(num))
  },
  fetchHomeMultidata(){
    dispatch(fetchHomeMultidataAction({name:'why',age:18}))
  }
})
export default connect(mapStateToProps,mapDispatchToProps)(home) 